package com.ujs.eduservice.controller.admin;


import com.ujs.commonutils.constant.R;
import com.ujs.eduservice.entity.subject.OneSubject;
import com.ujs.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2023-08-06
 */
@RestController
@RequestMapping("/eduservice/subject")
@Api(tags = "课程分类api")
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    // 获取课程分类
    // 获取上传过来的文件，把文件内容读取出来
    @ApiOperation("添加课程分类")
    @PostMapping("/addSubject")
    public R addSubject(@ApiParam(name = "file", value = "课程分类excel", required = true) MultipartFile file) {
        subjectService.saveSubject(file, subjectService);
        return R.ok();
    }

    @ApiOperation("获取课程分类数据，格式为json数组")
    @GetMapping("/getAllSubject")
    public R getAllSubject() {
        // 1688084298868482000
        // 1688084298818150402
        List<OneSubject> list = subjectService.getAllSubject();
        if (list!=null && list.size() > 0) return R.ok().data("data", list);
        else return R.error().message("分类数据为空");
    }
}

